/*
 * intController.h
 *
 * Author: Tarl Hahn
 * Version: 1.0
 * 
 * Header file simulating and interrupt controller.
 * The controller consumes IO requests for processing by IO devices and produces 
 * interrupts when the devices are completed, includes system timer
 *
 * Interrupt controller should be a new thread communicating with the CPU - a seperate thread -
 * This will provide an easy way to approximate the asycronicity between the CPU and all the  
 * different possible interrupts that could happen at any time.
 *
 */
 
#ifndef INTCTRL_H
#define INTCTRL_H

#include <pthread.h>
#include "SharedMem.h"
#include "devices.h"
 
typedef struct ctrl{

	DevicePtr timer;    // system timer.
	DevicePtr* devices; // an array of devices.
	int arraylen;       // length of the array of devices.
	SharedMemPtr mem; // the shared mem area
	pthread_mutex_t lock; // mutex lock
	pthread_t thread;     // thread variable
	
	// member functions
	int (*destruct)(struct ctrl*); // destroys the interrupt controller.
	char* (*toString)(struct ctrl*, int*); // toString
	
} intCtrl;

typedef intCtrl* intCtrlPtr;

intCtrlPtr intCtrl_init(SharedMemPtr mem, int* deviceArray, int arraylen); // interrupt controller initializor.
#endif
